package ihm.actions.character_creator;

import ihm.views.character_creator.CharacterCreator;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ImageIcon;

import systems.rpgBuilder.Faction;
import systems.rpgBuilder.RpgBuilder;

public class FactionSelectedAction 
implements ItemListener {

  private CharacterCreator charCreatorFrame;
  
  public FactionSelectedAction(CharacterCreator source)
  {
    this.charCreatorFrame = source;
  }

  @Override
  public void itemStateChanged(ItemEvent e){
    if(e.getItem() != null)
    {
      System.out.println("Faction selected");
      Faction factionSelected = RpgBuilder.getFactionsList().get(this.charCreatorFrame.getFactionComboBox().getSelectedIndex());
      //Update the Faction Icon
      this.charCreatorFrame.getFactionIconLabel().setText(" ");
      this.charCreatorFrame.getFactionIconLabel().setIcon(new ImageIcon(factionSelected.getPicturePath()));
      //Set enable the Classe Selector
      this.charCreatorFrame.getSelectClasseLabel().setEnabled(true);
      this.charCreatorFrame.getClasseComboBox().setEnabled(true);
      this.charCreatorFrame.getClasseIconLabel().setEnabled(true);
      //Update the class list
      this.charCreatorFrame.updateClasses();
    }
  }

}